package org.akomantoso.core.data;

import java.io.IOException;

import org.akomantoso.core.data.attribute.IdOpt;
import org.akomantoso.core.data.attribute.Link;
import org.akomantoso.core.data.attribute.Pos;
import org.akomantoso.core.data.type.PosType;
import org.akomantoso.core.io.Externalizable;
import org.akomantoso.core.io.Input;
import org.akomantoso.core.io.Output;
import org.akomantoso.core.io.OutputUtil;

/**
 * the complex type argumentType defines the empty content model and the list of attributes for metadata elements in the
 * analysis section.
 * 
 * <pre>
 * 	<xsd:complexType name="argumentType">
 * 		<xsd:attributeGroup ref="idopt" />
 * 		<xsd:attributeGroup ref="link" />
 * 		<xsd:attributeGroup ref="pos" />
 * 		<xsd:attribute name="upTo" type="xsd:anyURI" />
 * 	</xsd:complexType>
 * </pre>
 * 
 * @author <a href="mailto:jacques.militello@gmail.com">Jacques Militello</a>
 * 
 * @since http://www.akomantoso.org/1.0
 * 
 */
public abstract class ArgumentType implements IdOpt, Link , Pos , Externalizable{

	public static final String ATTRIBUTE_UPTO = "upTo";
	
	// IdOpt
	private String _id;
	private String _evolvingId;
	
	// Link
	private String _href;
	
	// Pos
	private PosType _pos;

	private String _upTo;
	
	/**
	 * @see org.akomantoso.core.data.attribute.IdOpt#getId()
	 */
	public String getId() {
		return _id;
	}

	/**
	 * @see org.akomantoso.core.data.attribute.IdOpt#setId(java.lang.String)
	 */
	public void setId(String id) {
		_id = id;
	}

	/**
	 * @see org.akomantoso.core.data.attribute.IdOpt#getEvolvingId()
	 */
	public String getEvolvingId() {
		return _evolvingId;
	}

	/**
	 * @see org.akomantoso.core.data.attribute.IdOpt#setEvolvingId(java.lang.String)
	 */
	public void setEvolvingId(String evolvingId) {
		_evolvingId = evolvingId;
	}
	
	/**
	 * @see org.akomantoso.core.data.attribute.Link#getHref()
	 */
	public String getHref() {
		return _href;
	}

	/**
	 * @see org.akomantoso.core.data.attribute.Link#setHref(java.lang.String)
	 */
	public void setHref(String href) {
		_href = href;
	}
	
	/**
	 * @see org.akomantoso.core.data.attribute.Pos#getPos()
	 */
	public PosType getPos() {
		return _pos;
	}

	/**
	 * @see org.akomantoso.core.data.attribute.Pos#setPos(org.akomantoso.core.data.type.PosType)
	 */
	public void setPos(PosType posType) {
		_pos = posType;
	}

	public String getUpTo() {
		return _upTo;
	}

	public void setUpTo(String upTo) {
		_upTo = upTo;
	}

	/**
	 * @see org.akomantoso.core.io.Externalizable#writeExternal(org.akomantoso.core.io.Output)
	 */
	public <T extends Output> void writeExternal(T out) throws IOException {
		OutputUtil.writeIdOpt(out, this);
		OutputUtil.writeLink(out, this);
		OutputUtil.writePos(out, this);
		OutputUtil.writeAttribute(out, ATTRIBUTE_UPTO, _upTo);
	}

	/**
	 * @see org.akomantoso.core.io.Externalizable#readExternal(org.akomantoso.core.io.Input)
	 */
	public <T extends Input> void readExternal(T in) throws IOException {
		_id = in.readAttribute(IdOpt.ATTRIBUTE_ID);
		_evolvingId = in.readAttribute(IdOpt.ATTRIBUTE_EVOLVING_ID);
		_href = in.readAttribute(Link.ATTRIBUTE);
		_pos = PosType.checkValueOf(in.readAttribute(Pos.ATTRIBUTE));
		_upTo = in.readAttribute(ATTRIBUTE_UPTO);
	}
	
}